import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class leader_rank_list extends StatefulWidget {
  leader_rank_list({Key key, this.rank_id}) : super(key: key);
  int rank_id;
  @override
  State<leader_rank_list> createState() => _leader_rank_listState();
}

class _leader_rank_listState extends State<leader_rank_list> {
  int rank_num = 0;

  List cartoon_rank = [
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai1',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaiha2',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai3',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai4',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai5',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai6',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai7',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai8',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai9',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
  ];

  List cartoon_rank1 = [
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai11',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai12',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai13',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai14',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai15',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai16',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai17',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai18',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
    {
      'cartoon_id': 1007,
      'imageUrl': 'http://www.itying.com/images/flutter/1.png',
      'name': 'haihaihai19',
      'author': '尾田荣一郎',
      'tage': 'rexue',
      'stae': '连载中'
    },
  ];

  ScrollController _scrollController = new ScrollController();
  @override
  void initState() {
    // TODO: implement initState
    print('进入' + widget.rank_id.toString());
    rank_num = 0;
    super.initState();
    _scrollController.addListener(() {
      if (_scrollController.position.pixels ==
          _scrollController.position.maxScrollExtent) {
        // _onLoadmore();
        // print('滑到了最底部');
        if (cartoon_rank.length <= 90) {
          cartoon_rank..addAll(cartoon_rank1);
          // print(cartoon_rank);
          rank_num = 0;
        }

        setState(() {});
      }

      // print('滑了');
    });
  }

  @override
  Widget build(BuildContext context) {
    return RefreshIndicator(
      onRefresh: () async {
        //模拟网络请求
        setState(() {
          rank_num = 0;
        });
        print('上拉刷新');
        await Future.delayed(Duration(milliseconds: 2000));
        //结束刷新
        return Future.value(true);
      },
      child: ListView(controller: _scrollController,
          // shrinkWrap: true,
          children: [
            Wrap(
              children: cartoon_rank.asMap().keys.map(((e) {
                // rank_num++;
                // print(e);
                if (e >= 99) return null;
                return GestureDetector(
                  onTap: () {
                    print(cartoon_rank[e]['cartoon']);
                    // print(_scrollController);
                  },
                  child: Container(
                    color: Colors.white,
                    margin: EdgeInsets.only(top: 0, left: 10),
                    height: 120,
                    child: Row(
                      children: [
                        Column(children: [
                          Container(
                            width: 35,
                            alignment: Alignment.topRight,
                            child: Text(
                              e > 2 && e < 9
                                  ? '0' + (e + 1).toString()
                                  : (e + 1).toString(),
                              style: TextStyle(
                                  fontSize: (e < 3) ? 70 : 30,
                                  fontWeight: FontWeight.w900,
                                  fontStyle: e == 0 ? FontStyle.italic : null,
                                  color: Color.fromRGBO(207, 152, 113, 1)),
                            ),
                          ),
                        ]),
                        Container(
                          width: 80,
                          height: 120,
                          padding: EdgeInsets.only(top: 10, bottom: 10),
                          child: Image(
                            fit: BoxFit.fill,
                            image: NetworkImage(cartoon_rank[e]['imageUrl']),
                          ),
                        ),
                        Column(
                          children: [
                            Container(
                              // color: Colors.red,
                              width: 120,
                              height: 45,
                              margin: EdgeInsets.only(top: 14, left: 10),
                              child: Text(
                                // cartoon_rank[e]['name'],
                                '11111111',
                                style: TextStyle(fontSize: 14),
                              ),
                            ),
                            Container(
                              width: 120,
                              margin: EdgeInsets.only(left: 10, bottom: 2),
                              alignment: Alignment.topLeft,
                              child: Text(
                                cartoon_rank[e]['author'],
                                style: TextStyle(
                                    fontSize: 11, color: Colors.black54),
                              ),
                            ),
                            Container(
                              width: 120,
                              margin: EdgeInsets.only(left: 10, bottom: 2),
                              alignment: Alignment.topLeft,
                              child: Text(
                                cartoon_rank[e]['tage'],
                                style: TextStyle(
                                    fontSize: 11, color: Colors.black54),
                              ),
                            ),
                            Container(
                              width: 120,
                              margin: EdgeInsets.only(left: 10, bottom: 2),
                              alignment: Alignment.topLeft,
                              child: Text(
                                cartoon_rank[e]['stae'],
                                style: TextStyle(
                                    fontSize: 11, color: Colors.black54),
                              ),
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
                );
              })).toList(),
            )
          ]),
    );
  }
}
